const fs = require('fire-fs')
// const path = require('fire-path')

const packageName = 'yd-translater'
let spaceVue = null

Editor.Panel.extend({
  // css style for panel
  style: fs.readFileSync(Editor.url('packages://' + packageName + '/panel/panel.css', 'utf8')),

  // html template for panel
  template: fs.readFileSync(Editor.url('packages://' + packageName + '/panel/panel.html', 'utf8')),

  ready() {
    spaceVue = new window.Vue({
      el: this.shadowRoot,
      data: {
        inputData: '',
        translateResult: '',
      },
      methods: {
        ydTranslate() {
          let content = this.inputData.trim()
          if (content) {
            Editor.Ipc.sendToMain('yd-translater:translation', content)

          } else {
            this.inputData = content
          }
        },
      }
      
    })

  },

  messages: {
    'set-result'(e, resultArr) {
      // Editor.log('翻译收到', resultArr)
      spaceVue.translateResult = resultArr.join(' ')
    }
  }
});